
##***********注意事项：在创建的时候需要把 open-service-gateway 替换成自己的网关应用名称


SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
--  Table structure for `d_config`
-- ----------------------------
DROP TABLE IF EXISTS `d_config`;
CREATE TABLE `d_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL COMMENT '配置名称',
  `value` varchar(50) NOT NULL COMMENT '配置值',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `comment` varchar(100) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_name` (`application_name`,`name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT=' {"comment":"基础配置表","prefix":"d_"}';

-- ----------------------------
--  Records of `d_config`
-- ----------------------------
BEGIN;
INSERT INTO `d_config` VALUES ('2', 'application.log.detail', 'false', now(), now(), 'open-service-gateway', '是否开启系统运行详细日志'), ('9', 'zuul.use.canary.filters', 'false', now(), now(), 'open-service-gateway', '是否开启灰度过滤器');
COMMIT;

-- ----------------------------
--  Table structure for `d_route`
-- ----------------------------
DROP TABLE IF EXISTS `d_route`;
CREATE TABLE `d_route` (
  `id` varchar(50) NOT NULL COMMENT '路由id',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `path` varchar(150) NOT NULL COMMENT '转发路径',
  `service_id` varchar(50) NOT NULL COMMENT ' {"comment":"服务ID","useObj":true,"objVal":"RouteService"} ',
  `strip_prefix` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否去除前缀 1是 0否',
  `retryable` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否重试 1是 0否',
  `custom_sensitive_headers` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否自定义敏感头信息 0否 1是   一般采用自定义敏感头1',
  `sensitive_headers` varchar(800) NOT NULL DEFAULT '' COMMENT '自定义的敏感头集合，多个以(英文)逗号分隔  ',
  `add_host_header` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否添加真实访问来源的host 默认false不添加',
  `status` int(2) NOT NULL DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  `sort` double(7,2) NOT NULL DEFAULT '0.00' COMMENT '排序 数值越小优先级越高',
  `domain_route_id` int(11) NOT NULL DEFAULT '0' COMMENT '{"comment":"根据域名路由的域名id","useObj":true,"objVal":"RouteDomain"}',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  `add_prefix` varchar(150) DEFAULT '' COMMENT '添加前缀',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_domain_route_id_path` (`application_name`,`domain_route_id`,`path`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"路由配置表","prefix":"d_"}';

-- ----------------------------
--  Records of `d_route`
-- ----------------------------
BEGIN;
INSERT INTO `d_route` VALUES ('iddefault', 'open-service-gateway', '/**', '_default_service_id', '1', '0', '1', '', '0', '1', '99999.00', '0', now(), now(), '默认路由地址');
COMMIT;

-- ----------------------------
--  Table structure for `d_route_domain`
-- ----------------------------
DROP TABLE IF EXISTS `d_route_domain`;
CREATE TABLE `d_route_domain` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `domain` varchar(100) NOT NULL COMMENT '域名',
  `status` int(2) NOT NULL DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `comment` varchar(50) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_domain` (`application_name`,`domain`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"路由域名配置表","prefix":"d_"}';

-- ----------------------------
--  Table structure for `d_route_service`
-- ----------------------------
DROP TABLE IF EXISTS `d_route_service`;
CREATE TABLE `d_route_service` (
  `id` varchar(50) NOT NULL COMMENT '服务ID',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `status` int(2) NOT NULL DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  `health_url` varchar(100) DEFAULT '' COMMENT '健康检查地址 空即不检查',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"路由服务配置表","prefix":"d_"}';

-- ----------------------------
--  Table structure for `d_route_service_url`
-- ----------------------------
DROP TABLE IF EXISTS `d_route_service_url`;
CREATE TABLE `d_route_service_url` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `service_id` varchar(50) NOT NULL COMMENT '{"comment":"服务ID","useObj":true,"objVal":"RouteService"}',
  `url` varchar(100) NOT NULL COMMENT '后端地址 如果是https的需要加端口',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `status` int(2) NOT NULL DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"},{"code":2,"name":"ill_health","desc":"不健康"}]}',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_service_id_url` (`service_id`,`url`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"路由服务具体后端地址配置表","prefix":"d_"}';

-- ----------------------------
--  Table structure for `d_route_version`
-- ----------------------------
DROP TABLE IF EXISTS `d_route_version`;
CREATE TABLE `d_route_version` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `version` varchar(20) NOT NULL COMMENT '版本号',
  `route_id` varchar(50) NOT NULL COMMENT '{"comment":"路由ID","useObj":true,"objVal":"Route"} ',
  `service_id` varchar(50) NOT NULL COMMENT ' {"comment":"服务ID","useObj":true,"objVal":"RouteService"} ',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  `status` int(2) NOT NULL DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_route_id_version` (`route_id`,`version`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"路由版本配置表","prefix":"d_"}';

-- ----------------------------
--  Table structure for `d_zuul_filter`
-- ----------------------------
DROP TABLE IF EXISTS `d_zuul_filter`;
CREATE TABLE `d_zuul_filter` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `application_name` varchar(45) DEFAULT NULL COMMENT '应用名称',
  `filter_id` varchar(100) DEFAULT NULL COMMENT '过滤器id',
  `filter_name` varchar(45) DEFAULT NULL COMMENT '名称',
  `revision` int(11) DEFAULT NULL COMMENT '版本',
  `status` int(2) DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  `progress` int(2) DEFAULT '0' COMMENT '{"comment":"当前所处进度","useEnum":true,"enumVals":[{"code":-1,"name":"unpublished","desc":"未发布"},{"code":2,"name":"canary","desc":"灰度"},{"code":1,"name":"published","desc":"发布中"}]}',
  `filter_code` longtext COMMENT 'filter代码',
  `filter_type` varchar(10) DEFAULT NULL COMMENT 'filter类型',
  `disable_property_name` varchar(45) DEFAULT NULL COMMENT '禁用属性',
  `filter_order` int(11) DEFAULT NULL COMMENT '顺序',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `comment` varchar(100) DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_filter_name` (`application_name`,`filter_name`),
  UNIQUE KEY `uk_filter_id` (`filter_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"网关过滤器配置表","prefix":"d_"}';

-- ----------------------------
--  Records of `d_zuul_filter`
-- ----------------------------
BEGIN;
INSERT INTO `d_zuul_filter` VALUES ('6', 'open-service-gateway', 'open-service-gateway:DomainPreFilter:pre', 'DomainPreFilter', '1', '1', '1', 'package filter.script.pre\n\nimport com.homedo.microservice.open.service.gateway.zuul.conf.DomainConf\nimport com.homedo.microservice.open.service.gateway.zuul.constant.ZuulConstant\nimport com.netflix.zuul.ZuulFilter\nimport com.netflix.zuul.context.RequestContext\nimport org.slf4j.Logger\nimport org.slf4j.LoggerFactory\n\npublic class DomainPreFilter extends ZuulFilter {\n    private static final Logger LOGGER = LoggerFactory.getLogger(DomainPreFilter.class);\n\n\n    @Override\n    String filterType() {\n        return \"pre\"\n    }\n\n    @Override\n    int filterOrder() {\n        return -1000\n    }\n\n    @Override\n    boolean shouldFilter() {\n        RequestContext requestContext = RequestContext.getCurrentContext();\n        Boolean isAccessedRouteDomainFilter = requestContext.get(ZuulConstant.ZUUL_IS_ACCESSED_ROUTE_DOMAIN_FILTER);\n        if (isAccessedRouteDomainFilter != null && isAccessedRouteDomainFilter) {\n            return false;\n        }\n\n        String domain = requestContext.getRequest().getServerName();\n        boolean inRouteDomainList = DomainConf.getInstance().getConfs().containsKey(domain);\n\n        if (requestContext.debugRequest()) {\n            LOGGER.info(\"[当前域名是:{},是否在域名过滤列表中:{}]\", domain, inRouteDomainList);\n        }\n\n        return inRouteDomainList;\n    }\n\n    @Override\n    Object run() {\n        RequestContext requestContext = RequestContext.getCurrentContext();\n        String domain = requestContext.getRequest().getServerName();\n        String routeAddPrefix = requestContext.get(ZuulConstant.ZUUL_ROUTE_ADD_PREFIX);\n        if (routeAddPrefix != null && routeAddPrefix.length() > 0) {\n            routeAddPrefix = routeAddPrefix + ZuulConstant.ZUUL_ROUTE_ADD_PREFIX_SPLIT + domain;\n        } else {\n            routeAddPrefix = domain;\n        }\n\n        if (requestContext.debugRequest()) {\n            LOGGER.info(\"[通过域名过滤配置，添加转发路径前缀为:{}]\", routeAddPrefix);\n        }\n\n        requestContext.put(ZuulConstant.ZUUL_ROUTE_ADD_PREFIX, routeAddPrefix);\n        requestContext.put(ZuulConstant.ZUUL_IS_ACCESSED_ROUTE_DOMAIN_FILTER, true);\n        return Boolean.TRUE;\n    }\n\n}', 'pre', 'zuul.DomainPreFilter.pre.disable', '-1000', now(), now(), '域名过滤器,必须放在自定义过滤器的第一位。第一位是-1000，其它过滤器靠后'), ('7', 'open-service-gateway', 'open-service-gateway:VersionPreFilter:pre', 'VersionPreFilter', '1', '1', '1', 'package filter.script.pre\n\nimport com.homedo.microservice.open.service.gateway.zuul.constant.ZuulConstant\nimport com.netflix.config.DynamicPropertyFactory\nimport com.netflix.config.DynamicStringProperty\nimport com.netflix.zuul.ZuulFilter\nimport com.netflix.zuul.context.RequestContext\nimport org.slf4j.Logger\nimport org.slf4j.LoggerFactory\n\npublic class VersionPreFilter extends ZuulFilter {\n    private static final Logger LOGGER = LoggerFactory.getLogger(VersionPreFilter.class);\n\n    private static final DynamicStringProperty VERSION_ROUTE_PARAMETER = DynamicPropertyFactory\n            .getInstance().getStringProperty(ZuulConstant.ZUUL_ROUTE_VERSION_PARAMETER, \"routeVersion\");\n\n\n    @Override\n    String filterType() {\n        return \"pre\"\n    }\n\n    @Override\n    int filterOrder() {\n        return -999\n    }\n\n    @Override\n    boolean shouldFilter() {\n        RequestContext requestContext = RequestContext.getCurrentContext();\n        Boolean isAccessedVersionPreFilter = requestContext.get(ZuulConstant.ZUUL_IS_ACCESSED_ROUTE_VERSION_FILTER);\n        if (isAccessedVersionPreFilter != null && isAccessedVersionPreFilter) {\n            return false;\n        }\n\n        String routeVersion = requestContext.getRequest().getParameter(VERSION_ROUTE_PARAMETER.get());\n        if (routeVersion == null || routeVersion.length() == 0) {\n            routeVersion = requestContext.getRequest().getHeader(VERSION_ROUTE_PARAMETER.get());\n        }\n        if (routeVersion == null || routeVersion.length() == 0) {\n            if (requestContext.debugRequest()) {\n                LOGGER.info(\"[请求中版本为空]\");\n            }\n            return false;\n        }\n\n        return true;\n    }\n\n    @Override\n    Object run() {\n        RequestContext requestContext = RequestContext.getCurrentContext();\n\n        String routeVersion = requestContext.getRequest().getParameter(VERSION_ROUTE_PARAMETER.get());\n        if (routeVersion == null || routeVersion.length() == 0) {\n            routeVersion = requestContext.getRequest().getHeader(VERSION_ROUTE_PARAMETER.get());\n        }\n\n        if (requestContext.debugRequest()) {\n            LOGGER.info(\"[通过版本过滤配置，添加转发路由配置:{}]\", routeVersion);\n        }\n\n        String routeAddPrefix = requestContext.get(ZuulConstant.ZUUL_ROUTE_ADD_PREFIX);\n        if (routeAddPrefix != null && routeAddPrefix.length() > 0) {\n            routeAddPrefix = routeAddPrefix + ZuulConstant.ZUUL_ROUTE_ADD_PREFIX_SPLIT + routeVersion;\n        } else {\n            routeAddPrefix = routeVersion;\n        }\n\n        requestContext.put(ZuulConstant.ZUUL_ROUTE_ADD_PREFIX, routeAddPrefix);\n        requestContext.put(ZuulConstant.ZUUL_IS_ACCESSED_ROUTE_VERSION_FILTER, true);\n        return Boolean.TRUE;\n    }\n\n}\n', 'pre', 'zuul.VersionPreFilter.pre.disable', '-999', now(), now(), '版本过滤器必须放在域名过滤器之后'), ('8', 'open-service-gateway', 'open-service-gateway:ZuulHostPreFilter:pre', 'ZuulHostPreFilter', '1', '1', '1', 'package filter.script.pre\n\nimport com.alibaba.fastjson.JSONObject\nimport com.homedo.microservice.open.service.gateway.bean.po.enhanced.RouteEnhanced\nimport com.homedo.microservice.open.service.gateway.util.ApplicationContextUtil\nimport com.homedo.microservice.open.service.gateway.zuul.conf.RouteConf\nimport com.homedo.microservice.open.service.gateway.zuul.constant.ZuulConstant\nimport com.homedo.microservice.open.service.gateway.zuul.routelocator.LocalRouteLocator\nimport com.netflix.zuul.ZuulFilter\nimport com.netflix.zuul.context.RequestContext\nimport org.slf4j.Logger\nimport org.slf4j.LoggerFactory\nimport org.springframework.cloud.netflix.zuul.filters.Route\nimport org.springframework.cloud.netflix.zuul.filters.RouteLocator\nimport org.springframework.http.HttpHeaders\nimport org.springframework.web.util.UrlPathHelper\n\nimport javax.servlet.http.HttpServletRequest\n\nimport static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.*\n\npublic class ZuulHostPreFilter extends ZuulFilter {\n    private static final Logger LOGGER = LoggerFactory.getLogger(ZuulHostPreFilter.class);\n\n    private UrlPathHelper urlPathHelper = new UrlPathHelper();\n    private RouteLocator routeLocator;\n\n    @Override\n    String filterType() {\n        return \"pre\"\n    }\n\n    @Override\n    int filterOrder() {\n        return 6\n    }\n\n    @Override\n    boolean shouldFilter() {\n        return true;\n    }\n\n    @Override\n    Object run() {\n        init();\n        RequestContext ctx = RequestContext.getCurrentContext();\n        final String requestURI = this.urlPathHelper.getPathWithinApplication(ctx.getRequest());\n        Route route = this.routeLocator.getMatchingRoute(requestURI);\n        if (route != null) {\n            RouteEnhanced routeEnhanced = RouteConf.getInstance().getConfs().get(route.getId());\n            if (routeEnhanced != null && routeEnhanced.getAddHostHeader() != null && routeEnhanced.getAddHostHeader()) {\n                String host = toHostHeader(ctx.getRequest());\n                ctx.addZuulRequestHeader(HttpHeaders.HOST, host);\n                ctx.put(ZuulConstant.ZUUL_IS_ACCESSED_ZUUL_HOST_PRE_FILTER, true);\n\n                if (ctx.debugRequest()) {\n                    LOGGER.info(\"[通过Host路由，添加访问来源的Host:{}--{}--{}]\", host, requestURI, JSONObject.toJSONString(route))\n                }\n            }\n        }\n    }\n\n    private String toHostHeader(HttpServletRequest request) {\n        int port = request.getServerPort();\n        if ((port == HTTP_PORT && HTTP_SCHEME.equals(request.getScheme()))\n                || (port == HTTPS_PORT && HTTPS_SCHEME.equals(request.getScheme()))) {\n            return request.getServerName();\n        } else {\n            return request.getServerName() + \":\" + port;\n        }\n    }\n\n    void init() {\n        if (routeLocator == null) {\n            synchronized (ZuulHostPreFilter.class) {\n                if (routeLocator == null) {\n                    routeLocator = ApplicationContextUtil.getApplicationContext().getBean(LocalRouteLocator.class);\n                }\n            }\n        }\n    }\n}\n', 'pre', 'zuul.ZuulHostPreFilter.pre.disable', '6', now(), now(), 'Host过滤器必须放置在PreDecorationFilter之后，PreDecorationFilter位置是5');
COMMIT;

-- ----------------------------
--  Table structure for `d_zuul_filter_default`
-- ----------------------------
DROP TABLE IF EXISTS `d_zuul_filter_default`;
CREATE TABLE `d_zuul_filter_default` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `application_name` varchar(45) DEFAULT NULL COMMENT '应用名称',
  `filter_id` varchar(100) DEFAULT NULL COMMENT '过滤器id',
  `filter_name` varchar(45) DEFAULT NULL COMMENT '名称',
  `revision` int(11) DEFAULT NULL COMMENT '版本',
  `status` int(2) DEFAULT '0' COMMENT '{"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"}]}',
  `progress` int(2) DEFAULT '0' COMMENT '{"comment":"当前所处进度","useEnum":true,"enumVals":[{"code":-1,"name":"unpublished","desc":"未发布"},{"code":2,"name":"canary","desc":"灰度"},{"code":1,"name":"published","desc":"发布中"}]}',
  `filter_type` varchar(10) DEFAULT NULL COMMENT 'filter类型',
  `disable_property_name` varchar(45) DEFAULT NULL COMMENT '禁用属性',
  `filter_order` int(11) DEFAULT NULL COMMENT '顺序',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_filter_name` (`application_name`,`filter_name`),
  UNIQUE KEY `uk_filter_id` (`filter_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"网关过滤器配置表--默认配置","prefix":"d_"}';

-- ----------------------------
--  Records of `d_zuul_filter_default`
-- ----------------------------
BEGIN;
INSERT INTO `d_zuul_filter_default` VALUES ('17', 'open-service-gateway', 'open-service-gateway:ServletDetectionFilter:error', 'ServletDetectionFilter', '1', '1', '1', 'pre', 'zuul.ServletDetectionFilter.pre.disable', '-3', now(), now(), ''), ('18', 'open-service-gateway', 'open-service-gateway:Servlet30WrapperFilter:error', 'Servlet30WrapperFilter', '1', '1', '1', 'pre', 'zuul.Servlet30WrapperFilter.pre.disable', '-2', now(), now(), ''), ('19', 'open-service-gateway', 'open-service-gateway:FormBodyWrapperFilter:error', 'FormBodyWrapperFilter', '1', '1', '1', 'pre', 'zuul.FormBodyWrapperFilter.pre.disable', '-1', now(), now(), ''), ('20', 'open-service-gateway', 'open-service-gateway:TracePostZuulFilter:error', 'TracePostZuulFilter', '1', '1', '1', 'post', 'zuul.TracePostZuulFilter.post.disable', '0', now(), now(), ''), ('21', 'open-service-gateway', 'open-service-gateway:SendErrorFilter:error', 'SendErrorFilter', '1', '1', '1', 'error', 'zuul.SendErrorFilter.error.disable', '0', now(), now(), ''), ('22', 'open-service-gateway', 'open-service-gateway:TracePreZuulFilter:error', 'TracePreZuulFilter', '1', '1', '1', 'pre', 'zuul.TracePreZuulFilter.pre.disable', '0', now(), now(), ''), ('23', 'open-service-gateway', 'open-service-gateway:DebugFilter:error', 'DebugFilter', '1', '1', '1', 'pre', 'zuul.DebugFilter.pre.disable', '1', now(), now(), ''), ('24', 'open-service-gateway', 'open-service-gateway:PreDecorationFilter:error', 'PreDecorationFilter', '1', '1', '1', 'pre', 'zuul.PreDecorationFilter.pre.disable', '5', now(), now(), ''), ('25', 'open-service-gateway', 'open-service-gateway:RibbonRoutingFilter:error', 'RibbonRoutingFilter', '1', '1', '1', 'route', 'zuul.RibbonRoutingFilter.route.disable', '10', now(), now(), ''), ('26', 'open-service-gateway', 'open-service-gateway:SimpleHostRoutingFilter:error', 'SimpleHostRoutingFilter', '1', '1', '1', 'route', 'zuul.SimpleHostRoutingFilter.route.disable', '100', now(), now(), ''), ('27', 'open-service-gateway', 'open-service-gateway:SendForwardFilter:error', 'SendForwardFilter', '1', '1', '1', 'route', 'zuul.SendForwardFilter.route.disable', '500', now(), now(), ''), ('28', 'open-service-gateway', 'open-service-gateway:SendResponseFilter:error', 'SendResponseFilter', '1', '1', '1', 'post', 'zuul.SendResponseFilter.post.disable', '1000', now(), now(), '');
COMMIT;

-- ----------------------------
--  Table structure for `r_config_relation`
-- ----------------------------
DROP TABLE IF EXISTS `r_config_relation`;
CREATE TABLE `r_config_relation` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `zuul_filter_id` varchar(100) NOT NULL DEFAULT '' COMMENT '{"comment":"网关ID唯一标志","useObj":true,"objVal":"ZuulFilter"}',
  `config_name` varchar(50) NOT NULL COMMENT '配置名称',
  `global` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否是全局配置 0否 1是',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_zuul_filter_id_config_name` (`application_name`,`zuul_filter_id`,`config_name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"配置关系查询表","prefix":"r_"}';

-- ----------------------------
--  Records of `r_config_relation`
-- ----------------------------
BEGIN;
INSERT INTO `r_config_relation` VALUES ('1', 'open-service-gateway', '__global_config_relation__', 'zuul.use.canary.filters', '1', now(), now()), ('2', 'open-service-gateway', '__global_config_relation__', 'application.log.detail', '1', now(), now());
COMMIT;


CREATE TABLE `e_alert_history` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `alerting_id` int(11) NOT NULL COMMENT '告警中的ID',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `service_id` varchar(50) NOT NULL COMMENT '{"comment":"服务ID","useObj":true,"objVal":"RouteService"}',
  `url` varchar(100) NOT NULL COMMENT '告警地址',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_alerting_id` (`alerting_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"告警历史表","prefix":"e_"}';

CREATE TABLE `e_alert_notice` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `alerting_id` int(11) NOT NULL COMMENT '{"comment":"告警中的ID","useObj":true,"objVal":"Alerting"}',
  `alert_user_id` int(11) NOT NULL COMMENT '{"comment":"告警通知人","useObj":true,"objVal":"AlertUser"}',
  `notice_total` int(11) NOT NULL COMMENT '通知限制总次数',
  `status` int(2) NOT NULL DEFAULT '1' COMMENT ' {"comment":"是否可用","useEnum":true,"enumVals":[{"code":1,"name":"effective","desc":"可用"},{"code":0,"name":"invalid","desc":"不可用"},{"code":2,"name":"finish","desc":"结束"}]}',
  `notice_count` int(11) NOT NULL DEFAULT '0' COMMENT '已通知次数',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_alerting_id_alert_user_id` (`alerting_id`,`alert_user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"告警通知表","prefix":"e_"}';

CREATE TABLE `e_alert_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `username` varchar(30) NOT NULL COMMENT '用户名',
  `phone_no` varchar(20) NOT NULL COMMENT '手机号码',
  `email` varchar(50) NOT NULL COMMENT '邮箱',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `comment` varchar(50) DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_username` (`application_name`,`username`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"告警用户配置表","prefix":"e_"}';

CREATE TABLE `e_alerting` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `application_name` varchar(45) NOT NULL,
  `service_id` varchar(50) NOT NULL COMMENT '{"comment":"服务ID","useObj":true,"objVal":"RouteService"}',
  `url` varchar(100) NOT NULL COMMENT '后端服务地址',
  `create_time` datetime NOT NULL COMMENT '应用名称',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_service_id_url` (`application_name`,`service_id`,`url`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"告警中服务器列表","prefix":"e_"}';

CREATE TABLE `e_health_checking_error_statistics` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `service_id` varchar(50) NOT NULL COMMENT '{"comment":"服务ID","useObj":true,"objVal":"RouteService"}',
  `url` varchar(100) NOT NULL COMMENT '后端服务地址',
  `count` int(11) NOT NULL DEFAULT '0' COMMENT '一定监控时间内发生检测错误的总数；达到总数之后就会被更新为不健康的地址；',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_service_id_url` (`application_name`,`service_id`,`url`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"一定时间内检测错误率统计","prefix":"e_"}';

CREATE TABLE `r_alert_user_route_service` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `application_name` varchar(45) NOT NULL COMMENT '应用名称',
  `service_id` varchar(50) NOT NULL COMMENT '{"comment":"服务ID","useObj":true,"objVal":"RouteService"}',
  `alter_user_id` int(11) NOT NULL COMMENT '{"comment":"告警通知人","useObj":true,"objVal":"AlertUser"}',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_application_name_service_id_alter_user_id` (`application_name`,`service_id`,`alter_user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='{"comment":"服务器组告警通知人配置表","prefix":"r_"}';


SET FOREIGN_KEY_CHECKS = 1;
